<?php 
	
$strBusca = get_request("strBusca");
$status = get_request("status");

$dataInicial=$_REQUEST["dataInicial"];
$dataFinal= $_REQUEST["dataFinal"];

$dql = "select o from Entities\OrdemServico o JOIN o.solicitante s where (o.id = :id or s.nome like :nome) AND (o.dataAbertura BETWEEN :dataInicial AND :dataFinal) ";

if($status != "TODOS"){
	$dql .= " AND o.status = :status ";	
}
$dql .= " order by o.id DESC ";
$q = $em->createQuery($dql);

$q->setParameter("id", $strBusca);
//ECHO change_data_from_Br_to_bd($dataInicial);
$q->setParameter("dataInicial", change_data_from_Br_to_bd($dataInicial));
$q->setParameter("dataFinal", change_data_from_Br_to_bd($dataFinal));
$q->setParameter("nome", "%$strBusca%");

if($status != "TODOS"){
	$q->setParameter("status", "$status");	
}


$oss = $q->getResult();

$xml ="";
foreach ($oss as $os){
	$xml .="<os>";
	$xml .=		"<id>{$os->getId()}</id>";
	$xml .=		"<dataAbertura>".getDateBrStringFromDate($os->getDataAbertura())."</dataAbertura>";
	$xml .=		"<dataFechamento>".getDateBrStringFromDate($os->getDataFechamento())."</dataFechamento>";
	$xml .=		"<morador>{$os->getSolicitante()->getNome()}</morador>";
	$xml .=		"<descricaoCurta>".substr($os->getDescricaoProblema(), 0, 150)."</descricaoCurta>";
	$xml .=		"<responsavel>{$os->getResponsavel()->getNome()}</responsavel>";
	$xml .=		"<local>{$os->getLocal()}</local>";
	$xml .=		"<status>{$os->getStatus()}</status>";
	$xml .="</os>";
	
}

echo $xml;


?>